<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>使用手册</title>
    <style>
     #header {
            width: 100%;
            background-color: #417690;
            padding: 1rem 15%;
            position: fixed;
            top: 0;
            height: 30px;
            font-size: 24px;
            color: #f5dd5d;
        }
        
        #footer {
            position: fixed;
            bottom: 0;
            width: 100%;
            background: #f8f9fa;
            padding: 1rem 15%;
            border-top: 1px solid #dee2e6;
            z-index: 1000;
        }

        body {
            display: flex;
            flex-direction: row;
            margin: 0;
            padding: 60px 0 60px; 
            height: calc(100vh - 120px); /* 调整高度计算 */
        }

        #toc {
            width: 13%;
            height: calc(100% - 50px);
            overflow-y: auto;
            border-right: 1px solid #ccc;
            padding: 1rem;
            padding-top: 2rem; 
            padding-left: 1rem;
            font-size: 16px;
            
        }

        #content {
            width: 80%;
            height: calc(100% - 50px);
            overflow-y: auto;
            padding-top: 2rem; 
            padding-left: 2rem;
            overflow-y: auto;
            line-height: 2.5;
            font-size: 18px;
            color: #417690;
        }

        #toc ul {
            list-style-type: none;
            padding: 0;
        }

        #toc li {
            margin-bottom: 0.5rem;
        }

        #toc a {
            text-decoration: none;
            color: #3b84d1;
            font-size: 16px;
        }

        #toc a:hover {
            text-decoration: underline;
        }
    </style>
    <script>
        document.addEventListener('DOMContentLoaded', function () {
            const toc = document.getElementById('toc');
            const content = document.getElementById('content');
            const headings = content.querySelectorAll('h1, h2, h3, h4, h5, h6');

            const tocList = document.createElement('ul');
            let currentLevel = 1;
            let currentUl = tocList;

            headings.forEach((heading, index) => {
                const level = parseInt(heading.tagName[1]);
                const listItem = document.createElement('li');
                const link = document.createElement('a');
                link.textContent = heading.textContent;
                link.href = `#heading-${index}`;
                heading.id = `heading-${index}`;

                // 添加折叠/展开图标
                const toggleIcon = document.createElement('span');
                toggleIcon.className = 'toggle-icon';
                toggleIcon.innerHTML = '&#9660;'; // 向下箭头
                toggleIcon.style.cursor = 'pointer';
                toggleIcon.style.marginRight = '5px';

                // 处理层级关系
                if (level > currentLevel) {
                    const newUl = document.createElement('ul');
                    currentUl.lastChild.appendChild(newUl);
                    currentUl = newUl;
                } else if (level < currentLevel) {
                    for (let i = level; i < currentLevel; i++) {
                        currentUl = currentUl.parentNode.parentNode;
                    }
                }

                currentLevel = level;
                listItem.appendChild(toggleIcon);
                listItem.appendChild(link);
                currentUl.appendChild(listItem);

                // 添加点击事件
                toggleIcon.addEventListener('click', function(e) {
                    e.stopPropagation();
                    const childUl = this.parentNode.querySelector('ul');
                    if (childUl) {
                        childUl.style.display = childUl.style.display === 'none' ? 'block' : 'none';
                        this.innerHTML = childUl.style.display === 'none' ? '&#9658;' : '&#9660;';
                    }
                });
            });

            toc.appendChild(tocList);
        });
    </script>

    <style>
        /* 添加折叠样式 */
        .toggle-icon {
            transition: transform 0.2s;
        }
        ul ul {
            display: none; /* 默认隐藏子层级 */
            margin-left: 15px;
        }
    </style>
</head>

<body>
    <div id="header">综维物资管理系统使用手册</div>
    <div id="toc"></div>
    <div id="content">
        {{ html_content|safe }}
    </div>
    <div id="footer">
        <div class="text-center" style="font-size: 12px; color: #417690;">
            <div class="text-muted">2025年 综维库存物资管理系统
                <div class="text-muted">copyright © 齐分创新工作室</div>
            </div>
        </div>
    </div>
</body>

</html>
    